﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace library
{
    public partial class person_info : Form
    {
        public MySqlConnection conn = new DBclass().getConn();
        public person_info()
        {
            InitializeComponent();
        }

        private void person_info_Load(object sender, EventArgs e)
        {
            textBox1.Text = User.uname;
            textBox2.Text = User.uID.ToString();
            textBox3.Text = User.college;
            textBox4.Text = User.major;
            textBox5.Text = User.identity;
            conn.Open();
            string sql = "select borrow_rule.maxnum 最大借阅数量（本）,borrow_rule.days 最大借阅时长（天）,borrow_rule.renew 最长续借时间（天）,borrow_rule.to_now 距今出版时间（年） from borrow_rule, user_info where user_info.identity = borrow_rule.identity and user_info.identity=@identity GROUP BY borrow_rule.identity";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.Parameters.Add("@identity", MySqlDbType.VarChar, 10).Value = User.identity;
            DataSet ds = new DataSet();
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            da.Fill(ds);
            //dataGridView1.DataSource = ds.Tables[0];
            DataTable dataTable = ds.Tables[0];
            string sql1 = "select count(*) 已借阅数量（本） from borrow_info where uID=@ID";
            MySqlCommand cmd1 = new MySqlCommand(sql1, conn);
            cmd1.Parameters.Add("@ID", MySqlDbType.Int32).Value = User.uID;
            DataSet ds1 = new DataSet();
            MySqlDataAdapter da1 = new MySqlDataAdapter(cmd1);
            da1.Fill(ds1);
            DataTable dataTable1 = ds1.Tables[0];
            string sql2 = "select count(*) 已预约数量（本） from booking_info where uID=@ID1";
            MySqlCommand cmd2 = new MySqlCommand(sql2, conn);
            cmd2.Parameters.Add("@ID1", MySqlDbType.Int32).Value = User.uID;
            DataSet ds2 = new DataSet();
            MySqlDataAdapter da2 = new MySqlDataAdapter(cmd2);
            da2.Fill(ds2);
            DataTable dataTable2 = ds2.Tables[0];
            dataTable.Columns.Add("已借阅数量（本）");
            dataTable.Columns.Add("已预约数量（本）");
            for (int i = 0; i < dataTable1.Rows.Count; i++)
            {
                string nums = dataTable1.Rows[i]["已借阅数量（本）"].ToString();
                dataTable.Rows[i]["已借阅数量（本）"] = nums;
            }
            for (int j = 0; j < dataTable2.Rows.Count; j++)
            {
                string nums1 = dataTable2.Rows[j]["已预约数量（本）"].ToString();
                dataTable.Rows[j]["已预约数量（本）"] = nums1;
            }
            dataGridView1.DataSource = dataTable;
            conn.Close();
        }
    }
}
